<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Models\DevelopHistory as Info;

class DevelopHistory extends Controller
{
    public function get()
    {
        return Info::select('id', 'number', 'time', 'value', 'is_show')->latest('number')->get();
    }

    public function new(Request $request)
    {
        Info::create([
            'time' => $request->time,
            'value' => $request->value,
        ]);

        return $this->code(200);
    }

    public function put(Request $request)
    {
        $id = $request->id;
        $info = Info::find($id);

        $name = $request->name;
        $value = $request->value;

        if ($name == 'delete') {
            $info->delete();
        } else {
            $info->$name = $value;
            $info->save();
        }

        return $this->code(200);
    }
}
